﻿namespace Webinator
{
    using Enums;
    using MultipleAttribute;

    /// <summary>
    /// Multiple attribute <c>Locator</c> builder.
    /// </summary>
    public static class ByAttribute
    {
        /// <summary>
        /// Find by any attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Any(string value)
        {
            return ReturnDefinedAttributes(AttributeIs.Any, value);
        }

        /// <summary>
        /// Find by any attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="contains">Indicates whether the attribute value should be an exact match.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Any(string value, bool contains)
        {
            return ReturnDefinedAttributes(AttributeIs.Any, value, contains);
        }

        /// <summary>
        /// Find by the <c>alt</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Alt(string value)
        {
            return ReturnDefinedAttributes(AttributeIs.Alt, value);
        }

        /// <summary>
        /// Find by the <c>alt</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="contains">Indicates whether the attribute value should be an exact match.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Alt(string value, bool contains)
        {
            return ReturnDefinedAttributes(AttributeIs.Alt, value, contains);
        }

        /// <summary>
        /// Find by the <c>class</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Class(string value)
        {
            return ReturnDefinedAttributes(AttributeIs.Class, value);
        }

        /// <summary>
        /// Find by the <c>class</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="contains">Indicates whether the attribute value should be an exact match.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Class(string value, bool contains)
        {
            return ReturnDefinedAttributes(AttributeIs.Class, value, contains);
        }

        /// <summary>
        /// Find by a custom attribute.
        /// </summary>
        /// <param name="attribute">The attribute.</param>
        /// <param name="value">The value.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Custom(string attribute, string value)
        {
            var definedAttributes = new DefinedAttributes();
            definedAttributes.Attributes.Add(new DefineAttribute(attribute, value));
            return definedAttributes;
        }

        /// <summary>
        /// Find by a custom attribute.
        /// </summary>
        /// <param name="attribute">The attribute.</param>
        /// <param name="value">The value.</param>
        /// <param name="contains">Indicates whether the attribute value should be an exact match.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Custom(string attribute, string value, bool contains)
        {
            var definedAttributes = new DefinedAttributes();
            definedAttributes.Attributes.Add(new DefineAttribute(attribute, value, contains));
            return definedAttributes;
        }

        /// <summary>
        /// Find if the attribute exists.
        /// </summary>
        /// <param name="attribute">The attribute to look for.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Exists(string attribute)
        {
            var definedAttributes = new DefinedAttributes();
            definedAttributes.Attributes.Add(new DefineAttribute(attribute));
            return definedAttributes;
        }

        /// <summary>
        /// Find by the <c>href</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Href(string value)
        {
            return ReturnDefinedAttributes(AttributeIs.Href, value);
        }

        /// <summary>
        /// Find by the <c>href</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="contains">Indicates whether the attribute value should be an exact match.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Href(string value, bool contains)
        {
            return ReturnDefinedAttributes(AttributeIs.Href, value, contains);
        }

        /// <summary>
        /// Find by the <c>id</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Id(string value)
        {
            return ReturnDefinedAttributes(AttributeIs.Id, value);
        }

        /// <summary>
        /// Find by the <c>id</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="contains">Indicates whether the attribute value should be an exact match.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Id(string value, bool contains)
        {
            return ReturnDefinedAttributes(AttributeIs.Id, value, contains);
        }

        /// <summary>
        /// Find by the <c>name</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Name(string value)
        {
            return ReturnDefinedAttributes(AttributeIs.Name, value);
        }

        /// <summary>
        /// Find by the <c>name</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="contains">Indicates whether the attribute value should be an exact match.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Name(string value, bool contains)
        {
            return ReturnDefinedAttributes(AttributeIs.Name, value, contains);
        }

        /// <summary>
        /// Find by the <c>src</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Src(string value)
        {
            return ReturnDefinedAttributes(AttributeIs.Src, value);
        }

        /// <summary>
        /// Find by the <c>src</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="contains">Indicates whether the attribute value should be an exact match.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Src(string value, bool contains)
        {
            return ReturnDefinedAttributes(AttributeIs.Src, value, contains);
        }

        /// <summary>
        /// Find by the <c>style</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Style(string value)
        {
            return ReturnDefinedAttributes(AttributeIs.Style, value);
        }

        /// <summary>
        /// Find by the <c>style</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="contains">Indicates whether the attribute value should be an exact match.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Style(string value, bool contains)
        {
            return ReturnDefinedAttributes(AttributeIs.Style, value, contains);
        }

        /// <summary>
        /// Find by the inner text.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Text(string value)
        {
            return ReturnDefinedAttributes(AttributeIs.Text, value);
        }

        /// <summary>
        /// Find by the inner text.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="contains">Indicates whether the attribute value should be an exact match.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Text(string value, bool contains)
        {
            return ReturnDefinedAttributes(AttributeIs.Text, value, contains);
        }

        /// <summary>
        /// Find by the <c>type</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Type(string value)
        {
            return ReturnDefinedAttributes(AttributeIs.Type, value);
        }

        /// <summary>
        /// Find by the <c>type</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="contains">Indicates whether the attribute value should be an exact match.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Type(string value, bool contains)
        {
            return ReturnDefinedAttributes(AttributeIs.Type, value, contains);
        }

        /// <summary>
        /// Find by the <c>value</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Value(string value)
        {
            return ReturnDefinedAttributes(AttributeIs.Value, value);
        }

        /// <summary>
        /// Find by the <c>value</c> attribute.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="contains">Indicates whether the attribute value should be an exact match.</param>
        /// <returns>
        /// The attribute to use in the <c>Locator</c>.
        /// </returns>
        public static DefinedAttributes Value(string value, bool contains)
        {
            return ReturnDefinedAttributes(AttributeIs.Value, value, contains);
        }

        /// <summary>
        /// Creates an instance of the <c>Defined Attributes</c> class.
        /// </summary>
        /// <param name="attributeIs">The attribute.</param>
        /// <param name="value">The value.</param>
        /// <returns>
        /// An instance of the <c>Defined Attributes</c> class.
        /// </returns>
        private static DefinedAttributes ReturnDefinedAttributes(AttributeIs attributeIs, string value)
        {
            var definedAttributes = new DefinedAttributes();
            definedAttributes.Attributes.Add(new DefineAttribute(attributeIs, value));
            return definedAttributes;
        }

        /// <summary>
        /// Creates an instance of the <c>Defined Attributes</c> class.
        /// </summary>
        /// <param name="attributeIs">The attribute.</param>
        /// <param name="value">The value.</param>
        /// <param name="contains">Indicates whether the attribute value should be an exact match.</param>
        /// <returns>
        /// An instance of the <c>Defined Attributes</c> class.
        /// </returns>
        private static DefinedAttributes ReturnDefinedAttributes(AttributeIs attributeIs, string value, bool contains)
        {
            var definedAttributes = new DefinedAttributes();
            definedAttributes.Attributes.Add(new DefineAttribute(attributeIs, value, contains));
            return definedAttributes;
        }
    }
}